//login module
import { makeAutoObservable } from "mobx"
import { http, setToken, getToken, removeToken } from "@/utils"
class LoginStore {
  token = getToken() || '' //取到用本地的 取不到为空值
  constructor() {
    //响应式
    makeAutoObservable(this)
  }
  getToken = async ({ mobile, code }) => {
    //调用登录接口
    const res = await http.post('http://geek.itheima.net/v1_0/authorizations', {
      mobile, code
    })
    //存入token
    console.log(res.data)
    this.token = res.data.token
    //存入localstorage
    setToken(this.token)

  }
  loginOut = () => {
    this.token = ''
    removeToken()
  }
}
export default LoginStore